package com.wwdx.service;

import com.google.common.collect.Lists;
import com.wwdx.model.WwdxMerchantProductModel;
import com.wwdx.model.WwdxThemeModel;
import com.wwdx.model.WwdxVipProductModel;
import lombok.Data;

import java.util.List;

/**
 * @author liguoliang
 * @date 2018/1/31 18:54
 */
public interface WwdxMerchantProductServiceI extends BaseServiceI<WwdxMerchantProductModel> {

    Long selectModelCount(WwdxMerchantProductModel model);

    List<WwdxMerchantProductModel> selectModelList(WwdxMerchantProductModel model, Integer page, Integer rows);

    WwdxMerchantProductModel isExits(String merchant_id, Long product_id);

    List<WwdxMerchantProductModel> list(String merchant_id);

    /**
     * 获取产品列表
     */
    default List<WwdxMerchantProductDTO> getProductList(List<WwdxMerchantProductModel> list, WwdxThemeServiceI wwdxThemeService, WwdxVipProductServiceI wwdxVipProductService){
        List<WwdxMerchantProductDTO> wwdxMerchantProductDTOS = Lists.newArrayListWithExpectedSize(list.size());
        list.forEach(wwdxMerchantProductModel -> {
            WwdxMerchantProductDTO dto = new WwdxMerchantProductDTO();
            Long product_id = wwdxMerchantProductModel.getProduct_id();
            WwdxVipProductModel wwdxVipProductModel = wwdxVipProductService.getByProductId(product_id);
            if (wwdxVipProductModel!=null){
                dto.setProductName(wwdxVipProductModel.getProduct_name());
            }
            WwdxThemeModel wwdxThemeModel = wwdxThemeService.getByThemeId(product_id);
            if (wwdxThemeModel!=null){
                dto.setProductName(wwdxThemeModel.getTitle());
            }
            dto.setProductId(product_id);
            wwdxMerchantProductDTOS.add(dto);
        });
        return wwdxMerchantProductDTOS;
    }

    @Data
    class WwdxMerchantProductDTO {
        private Long productId;
        private String productName;
    }
}